﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using CSharp.Libs.Koc;


namespace KocTestCitySelector
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        private Kernel _KRNL = null;

        public MainWindow()
        {
            InitializeComponent();

            _KRNL = new Kernel();
            kocKernel2Control1.Initialize(_KRNL);
            kocKernel2Control1.ViewModel.AfterServerChange += new CSharp.Libs.WPF.UserControls.KocKernel2ViewModel.AfterServerChangeEventHandler(ViewModel_AfterServerChange);
            kocKernel2Control1.ViewModel.AfterUserChange += new CSharp.Libs.WPF.UserControls.KocKernel2ViewModel.AfterUserChangeEventHandler(ViewModel_AfterUserChange);

            kocCitySelector1.Initialize(_KRNL);
            kocCitySelector1.ViewModel.ServerNr = kocKernel2Control1.ViewModel.ServerId;
            if (kocKernel2Control1.ViewModel.SelectedUser != null) { kocCitySelector1.ViewModel.UserFbUid = kocKernel2Control1.ViewModel.SelectedUser.FbUid; }

            kocKnightSelector1.Initialize(_KRNL);
            kocKnightSelector1.ViewModel.ServerNr = kocKernel2Control1.ViewModel.ServerId;
            if (kocKernel2Control1.ViewModel.SelectedUser != null) { kocKnightSelector1.ViewModel.UserFbUid = kocKernel2Control1.ViewModel.SelectedUser.FbUid; }

            //messageLoggingTextBox1.InitViewModel(KRNL.ML);
            //postHandlerControl1.InitViewModel(kocHireKnightControl1.ViewModel.PH);

            _KRNL.LoggingEnabled = true;
            _KRNL.LogTrafficMonitor = true;
            _KRNL.LogPostHandler = true;

            kocCitySelector1.ViewModel.CitySelected += new CSharp.Libs.WPF.UserControls.KocCitySelectorViewModel.CitySelectedEventHandler(ViewModel_CitySelected);
        }

        //Kernel control events
        void ViewModel_AfterUserChange(object sender, CSharp.Libs.WPF.UserControls.UserChangeEventArgs ucea)
        {
            kocCitySelector1.ViewModel.UserFbUid = ucea.NewUser.FbUid;
            kocKnightSelector1.ViewModel.UserFbUid = ucea.NewUser.FbUid;
        }

        void ViewModel_AfterServerChange(object sender, CSharp.Libs.WPF.UserControls.ServerChangeEventArgs scea)
        {
            kocCitySelector1.ViewModel.ServerNr = scea.NewServerId;
            kocKnightSelector1.ViewModel.ServerNr = scea.NewServerId;
        }



        //city and knight events
        void ViewModel_CitySelected(object sender, CSharp.Libs.WPF.UserControls.SelectedCityEventArgs ssea)
        {
            this.Title = ssea.SelectedCity.CityName;
            kocKnightSelector1.ViewModel.SelectedCityId = (int)ssea.SelectedCity.CityID;
        }
    }
}
